﻿using DimensionData.Data2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPPEI.PM
{
    [Serializable]
    public class WorkSheetRow
    {
        /// <summary>
        /// 此行的完整工作项编号组合
        /// C01\C0101\C010101
        /// </summary>
        public string WorkItemCodePath { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int State { get; set; }

        [NonSerialized]
        public DRow YDRow;

        public List<WorkSheetCell> CellCollection { get; set; }

        public object this[int itemCount, string stageCodePath]
        {
            get
            {
                if (string.IsNullOrEmpty(stageCodePath))
                {
                    // 取item的信息
                    for (int index = 0; index < YDRow.Items.Length; index++)
                    {
                        DItem dItem = YDRow.Items[index];
                        if (dItem.Level == itemCount)
                        {
                            return dItem.Name;
                        }
                    }
                }
                else
                {
                    for (int index = 0; index < CellCollection.Count; index++)
                    {
                        if (CellCollection[index].Path.EndsWith(stageCodePath))
                        {
                            return CellCollection[index].Value;
                        }
                    }
                }
                return null;
            }
            set
            {
                if (string.IsNullOrEmpty(stageCodePath))
                {
                    // 取item的信息
                    for (int index = 0; index < YDRow.Items.Length; index++)
                    {
                        DItem dItem = YDRow.Items[index];
                        if (dItem.Level == itemCount)
                        {
                            dItem.Name = value.ToString();
                        }
                    }
                }
                else
                {
                    for (int index = 0; index < CellCollection.Count; index++)
                    {
                        if (CellCollection[index].Path.EndsWith(stageCodePath))
                        {
                            CellCollection[index].Value = value;
                            CellCollection[index].State = BD_State.Changed;
                        }
                    }
                }
            }
        }

        public WorkSheetRow()
        {
            CellCollection = new List<WorkSheetCell>();
        }
    }
}
